﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Soft.Service
{

    /// <summary>
    /// 封装调用方法的指令
    /// </summary>
    [Serializable]
    public struct CallMethodInstruction : IEquatable<CallMethodInstruction>, IComparable<CallMethodInstruction>
    {
        /// <summary>
        /// 封装调用方法的指令
        /// </summary>
        /// <param name="fucntionCode">功能号</param>
        /// <param name="jsonParams">调用的参数</param>
        public CallMethodInstruction(string fucntionCode, string jsonParams = "")
        {
            this.mFunctionCode = fucntionCode;
            this.JsonParams = jsonParams;
            this.ClientIPAddress = IPAddress.None;
        }


        /// <summary>
        /// 功能号
        /// </summary>
        public string FunctionCode
        {
            get
            {
                return this.mFunctionCode;
            }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    throw new ArgumentNullException("value");
                }
                this.mFunctionCode = value.Trim().ToUpper();
            }
        }

        /// <summary>
        /// 调用参数
        /// </summary>
        public string JsonParams { get; set; }


        /// <summary>
        /// 客户端IP地址
        /// </summary>
        public IPAddress ClientIPAddress { get; set; }


        /// <summary>
        /// 比较两个方法调用是否一样
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(CallMethodInstruction other)
        {
            return this.mFunctionCode.CompareTo(other.FunctionCode);
        }

    
        public bool Equals(CallMethodInstruction other)
        {
            return this.mFunctionCode == other.mFunctionCode;
        }


        private string mFunctionCode;
    }
}
